package com.zuqiuzhandui.liveing.common;

import com.code19.library.GsonUtil;
import com.code19.library.L;
import com.code19.library.SPUtils;
import com.zuqiuzhandui.liveing.model.resultModel.LoginRs;
import com.zuqiuzhandui.liveing.myInterfacce.Constant;

/**
 * @author MC
 *         Description   用户信息管理
 * @date 创建时间 2016-10-12
 */

public class UserInfomationManage implements Constant {


    public static void putAccessKey(String accessKey) {
        SPUtils.setSP(MyApplication.getInstance(), null, "" + ACCESS_KEY, accessKey);
    }

    public static String getAccessKey() {
        return (String) SPUtils.getSp(MyApplication.getInstance(), Constant.ACCESS_KEY, "");
    }

    public static void putRefreshKey(String refreshKey) {
        SPUtils.setSP(MyApplication.getInstance(), null, "" + REFRESH_KEY, refreshKey);
    }
    public static String getRefreshKey() {
        return (String) SPUtils.getSp(MyApplication.getInstance(), REFRESH_KEY, "");
    }
    public static void putUserInformation(String userInfomation) {
        SPUtils.setSP(MyApplication.getInstance(), null, "" + USER_INFOMATION, userInfomation);
    }
    public static String getUserInformation() {
        return (String) SPUtils.getSp(MyApplication.getInstance(), USER_INFOMATION, "");
    }


    public static void savaUser(LoginRs o) {
        L.d(GsonUtil.objectToJson(o));
        LoginRs.AppTokenBean appToken = o.getAppToken();
        LoginRs.MemberBean member = o.getMember();

        putAccessKey(appToken.getAccessKey());
        putRefreshKey(appToken.getRefreshKey());
        putUserInformation(GsonUtil.objectToJson(member));
    }

    public static void removeUser(){
        SPUtils.cleanAllSP(MyApplication.getInstance());
    }
}
